<?php
require(dirname(__FILE__)."/../inc/common.inc.php");
admin(6);
$uadmin=$db->get_one("SELECT * FROM {$pre}admin where u_id='$admin_id'");

$list1=trim($adminarr['u_lanid'],',');
if($adminarr['u_group']!=1){
$isql2.=" and a.u_gid in ($list1) "; 
}
?>

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="js/html5.js"></script>
<script type="text/javascript" src="js/respond.min.js"></script>
<script type="text/javascript" src="js/PIE_IE678.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="css/H-ui.css"/>
<link type="text/css" rel="stylesheet" href="css/H-ui.admin.css"/>
<link type="text/css" rel="stylesheet" href="font/font-awesome.min.css"/>
<!--[if IE 7]>
<link href="font/font-awesome-ie7.min.css" rel="stylesheet" type="text/css" />
<![endif]-->
<title>管理员列表</title>
</head>
<body>
<?php
function ttre($str){
	if (!$str){
		return '0';
	}else{
		return $str;
	}
}

if ($action=='reg') {
	if (!empty($subit)){
		$u_lanid=@implode(',',$u_lanid);

		if (!empty($uid)){
			if(!empty($u_pass)){
				$sqli=",u_pass='".md5($u_pass)."'";
			}

       $i=0;
      $query1 = $db->query("select * from {$pre}menu where m_fid<>'0' order by  m_id asc");
      while($rs1 = $db->fetch_array($query1)){  
        $b='ssion'.$rs1['m_id'];
        $cc=$$b;
        $ssion[$rs1['m_id']]=ttre($cc);
        if($ssion[$rs1['m_id']]<>0){
          $i++;
          if($i=='1'){
            $ddr.=$ssion[$rs1['m_id']];
          }else{
            $ddr.=','.$ssion[$rs1['m_id']];
          }
        }
      }
			

			$query = $db->query("update {$pre}admin set u_phone='{$u_phone}',u_ssion='{$ddr}',u_title='{$u_title}',u_content='{$u_content}',u_gid='{$u_gid}',u_group='{$u_group}',u_lanid='{$u_lanid}',u_or='{$u_or}' {$sqli}  where u_id='{$uid}'");
			logo('修改用户');
			refreshto(($backurl?base64_decode($backurl):'?'),'修改成功!',2);
		}else{

			$grs2 = $db->get_one("select ssion from {$pre}admin_group where id='$u_group'");
			//这里要涉及到数组求交集
			$add_g_arr=explode(',',$grs2['ssion']);//
			$add_g_arr1=explode(',',$adminarr['u_ssion']);//
			$add_g_arr2=array_intersect($add_g_arr,$add_g_arr1);
			$grs2['ssion']=implode(',',$add_g_arr2);
			
			
			$addu = $db->get_one("select * from {$pre}admin where u_name='$u_name'");
			if($addu){	
				refreshto('?action=reg','添加失败,已经存在该用户名!',2);
			}else{
				list($uid, $username, $email) = $data;

                    $db->query("INSERT INTO {$pre}admin (u_phone,u_name,u_pass,u_ssion,u_time,u_title,u_content,u_gid,u_adminid,u_group,u_lanid,u_or) 
VALUES ('$u_phone','".filtrate($u_name)."','".md5($u_pass)."','".$grs2['ssion']."','".$timestamp."','$u_title','$u_content','$u_gid','$admin_id','$u_group','$u_lanid','$u_or')");
                    logo('添加用户');
                    refreshto(($backurl?base64_decode($backurl):'?'),'添加成功!',2);
              
			}
		}		
	}	
	if (!empty($uid)){
		$dbrs = $db->get_one("select * from {$pre}admin where u_id='$uid'");
		if(!$dbrs){
			showerr('权限错误');
		}
		$ssions = explode(",",$dbrs['u_ssion']);
	}
	
?>
<div class="pd-20">
  <div class="Huiform">
  <script>
function find_select1(name,to_find_str)
{
	var select1 = document.getElementById(name);
	var find_str = document.getElementById(to_find_str).value;
	if(select1){
		for(var i=0;i<select1.options.length;i++){
			text=select1.options[i].text;
			if( text && text.indexOf(find_str)!=-1)  {  
				select1.options[i].selected=true;
			}
		}
	
	}
		
}
</script>
  <table class="table table-border table-bordered table-bg">
    <form name="zhuce12"  method="post" target="_parent" >
        <input type="hidden" name="backurl" value="<?=$backurl?>">
    <tr>
    	<td width="20%" height="25" align="right" bgcolor="#FFFFFF" class="bgcolor">用户名：</td>
      <td width="80%" height="25" bgcolor="#FFFFFF" class="bgcolor">
          <input class="input-text" type="text" name="u_name" <?php if(!empty($dbrs))echo 'disabled'; ?> value="<?=$dbrs['u_name']?>" />
          <input class="" type="hidden" name="userid" value="<?=$dbrs['u_name']?>" >
      </td>
    </tr>
    <tr>
    	<td height="25" align="right" bgcolor="#FFFFFF" class="bgcolor">密码：</td>
      <td height="25" bgcolor="#FFFFFF" class="bgcolor"><input class="input-text" type="password" name="u_pass"><?php if($dbrs){?>(不修改请留空)<?php }?></td>
    </tr>
  
    <tr>
    	<td width="20%" height="25" align="right" bgcolor="#FFFFFF" class="bgcolor">姓名：</td>
      <td width="80%" height="25" bgcolor="#FFFFFF" class="bgcolor">
          <input class="input-text" type="text" name="u_title"  value="<?=$dbrs['u_title']?>" />
          <input class="input-text" type="hidden" name="u_title_old"  value="<?=$dbrs['u_title']?>" />
      </td>
    </tr>  
    <tr>
    	<td width="20%" height="25" align="right" bgcolor="#FFFFFF" class="bgcolor">电话：</td>
      <td width="80%" height="25" bgcolor="#FFFFFF" class="bgcolor">
          <input class="input-text" type="text" name="u_phone"  value="<?=$dbrs['u_phone']?>" />
          <input class="input-text" type="hidden" name="u_phone_old"  value="<?=$dbrs['u_phone']?>" />
      </td>
    </tr>
    
    

    
      <tr>
    	<td width="20%" height="25" align="right" bgcolor="#FFFFFF" class="bgcolor">启用：</td>
      <td width="80%" height="25" bgcolor="#FFFFFF" class="bgcolor"><input type="checkbox" name="u_or"  value="1"   <?=$dbrs['u_or']==1?'checked':''?> /></td>
    </tr>
		
	



    <tr>
      <td height="25" align="right" bgcolor="#FFFFFF" class="bgcolor">所属组：</td>
      <td height="25" bgcolor="#FFFFFF" class="bgcolor"><select name="u_group" class="select">
<?php
$query = $db->query("select id,title from {$pre}admin_group order by id asc");
while($rs = $db->fetch_array($query)){	
if($rs['id']==1){
if($adminarr['u_group']==1){
?>	  
<option  value="<?=$rs['id']?>" <?=$rs['id']==$dbrs['u_group']?'selected':''?>><?=$rs['title']?></option>
<?php
}
}else{
?>
<option  value="<?=$rs['id']?>" <?=$rs['id']==$dbrs['u_group']?'selected':''?>><?=$rs['title']?></option>
<?php
}
}
?>
	  </select></td>
    </tr>
    
    
     <tr>
      <td height="25" align="right" bgcolor="#FFFFFF" class="bgcolor">所在部门：</td>
      <td height="25" bgcolor="#FFFFFF" class="bgcolor"><select name="u_gid" id="yckid" class="input-text">
      <option value="">请选择</option>
<?php
$query = $db->query("select id,name from {$pre}department order by id asc");
while($rs = $db->fetch_array($query)){	
?>
<option  value="<?=$rs['id']?>" <?=$rs['id']==$dbrs['u_gid']?'selected':''?>><?=$rs['name']?></option>
<?php
}
?>
	  </select>
      
       <input value="" id="to_find_str2" size="16" class="input-text"/><input value="查询"  class="btn btn-success radius" onClick="find_select1('yckid','to_find_str2')" type="button" />
          <input type="hidden" value="<?=$dbrs['u_gid']?>" name="u_gid_old">
      </td>
    </tr>
    
    
         <tr>
       <td height="25" align="right" bgcolor="#FFFFFF" class="bgcolor">管理部门：</td>
       <td height="25" bgcolor="#FFFFFF" class="bgcolor">
		   


			 
		   
		   
		    <?php
$query = $db->query("select id,name from {$pre}department  where id in ($list1)order by id asc");
while($rs = $db->fetch_array($query)){	
?>
    <label style="overflow:hidden;width:140px;float:left;"><input name="u_lanid[]" type="checkbox"  value="<?=$rs['id']?>" <?=in_array($rs['id'],@explode(',',$dbrs['u_lanid']))?'checked':''?>  ><?=$rs['name']?></label>
		 <?php
}
?>
		   
			 
			 
			 
			 
			 
			 </td>
     </tr>
		

		
		
    
  
     <?php if(!empty($uid)){ ?>

     <tr>
    	<td height="25" align="right" bgcolor="#FFFFFF" class="bgcolor">权限信息：</td>
      <td height="25" bgcolor="#FFFFFF" class="bgcolor">
      <?php
      $query1 = $db->query("select * from {$pre}menu where m_fid='0' order by  m_id asc");
		while($rs1 = $db->fetch_array($query1)){	
		unset($rs4);
		
		$quert2 = $db->query("select * from {$pre}menu where m_fid='".$rs1['m_id']."' and m_id in(".$adminarr['u_ssion'].") order by  m_id asc");
		while($rs3 = $db->fetch_array($quert2)){
			$rs4[]=$rs3;
		}

		if($rs4){
	  ?>
   		<div style="height:22px; line-height:22px; color:#FF0000;">&nbsp;&nbsp;<?=$rs1['m_title']?></div>
            <div style="padding-left:30px; color:#CC6600;">
            <?php
           
			foreach($rs4 as $keys=>$rs2){	
			?>
      			<input name="ssion<?=$rs2['m_id']?>" type="checkbox" value="<?=$rs2['m_id']?>" id="chkAdv<?=$rs2['m_id']?>" <?php if($uid){ if (@in_array($rs2['m_id'],$ssions)) echo 'checked'; }?> ><label for="chkAdv<?=$rs2['m_id']?>"><?=$rs2['m_title']?></label>&nbsp;
             <?php
             }
			?>
            </div>
      <?php 
	  }
	  }
	  ?>
      <?php
      if($uid==$adminarr['u_id']){
	  ?><br><font color="#FF0000">请勿随意修改自己的权限否则将出现权限不正常</font><?php }?>      </td>
    </tr> 
    <?php
	}
	?>



<tr>
    	<td width="20%" height="25" align="right" bgcolor="#FFFFFF" class="bgcolor">介绍：</td>
      <td width="80%" height="25" bgcolor="#FFFFFF" class="bgcolor"><textarea name="u_content" class="textarea"  rows="5"><?=$dbrs['u_content']?></textarea></td>
    </tr>
    <tr>
   	  <td height="25" colspan="2" align="center" bgcolor="#FFFFFF" class="bgcolor"><input type="submit" name="subit" value="<?php if ($uid){?>修改<?php } else{?>添加<?php }?>"  onClick="if (zhuce12.u_name.value.length<1){alert('请输入你要添加的用户名！');zhuce12.u_name.focus();return false;};<?php if (!$uid){?>if(zhuce12.u_pass.value.length<1){alert('密码不能为空！');zhuce12.u_pass.focus();return false;};<?php }?>  return  chckform()" class="btn btn-success radius"  /></td>
    </tr>
    </form>
</table>

<?php
}else{
if($del){
	if (empty($id)){
		refreshto($FROMURL,'删除失败!',2);
	}
 
        $query = $db->query("DELETE FROM chen_admin WHERE u_id='{$id}'");
        logo('删除人员');
        refreshto($FROMURL,'删除成功!',2);
    
}
?>
<nav class="Hui-breadcrumb"> <?=get_category(6)?> <a class="btn btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.href='admin.php';" title="刷新" ><i class="icon-refresh"></i></a></nav>
<div class="pd-20">
  <div class="">
    <form class="Huiform" method="get" action="?" >
    <input type="hidden" name="page" value="1">
      <input type="text" placeholder="输入关键词查询" autocomplete="off" value="<?=$keyword?$keyword:''?>" name="keyword"  class="input-text">
      部门选择：
      <select name="deptchoice" id="deptchioce"  class="select">
      <option value="">选择全部</option>
      <?php 
	  $seldept=$db->query("SELECT id AS deptid,name AS deptname FROM chen_department where id in ({$list1}) order by id asc");
	  while($seldeptid=$db->fetch_array($seldept)){
	  ?>
      <option value="<?=$seldeptid['deptid']?>"  <?=$deptchoice==$seldeptid['deptid']?'selected':''?> ><?=$seldeptid['deptname']?></option>
      <?php
		  }
	  ?>
      </select>
      权限分组：
      <select class="select"  size="1" name="gid">
        <option value="">选择分组</option>
        <?php
        $query = $db->query("select * from {$pre}admin_group where 1=1 order by id asc");
		while($rs = $db->fetch_array($query)){	
		if ($gid==$rs['id'])
		{
			$selected1="selected";
		}
		else
		{
			$selected1='';
		}
			echo "<option value=\"".$rs['id']."\" {$selected} {$selected1}>".$rs['title']."</option>";
		}
		?>
      </select>
      <button type="submit" class="btn btn-success" id="12" name="12" value="12" ><i class="icon-plus"></i> 搜索</button>

        <button type="button" class="btn btn-success" id="122" name="1223" value="12"  onClick="article_class_edit('0','1000','600','员工管理','admin.php?action=reg&backurl=<?=base64_encode($WEBURL)?>')"  ><i class="icon-plus"></i> 注册用户</button>
    </form>
</div>
     <table class="table table-border table-bordered table-bg">
         <thead>
         <tr class="text-c">
             <th width="84">ID</th>
             <th width="128">登录名</th>
             <th width="161">姓名</th>
             <th width="161">电话</th>
             <th width="322">所在部门</th>
              
             <th width="230">角色</th>
             <th width="339">加入时间</th>
             <th width="132">是否已启用</th>
             <th width="84">操作</th>
         </tr>
         </thead>
         <tbody>
         <?php
         $rows=20;
         if($page<1){
             $page=1;
         }
         $min=($page-1)*$rows;
         if($adminarr['u_gid']==0){
             $isql.="";
         }
         if($keyword!=''  ){
             $isql.=" and ( a.u_name like '%{$keyword}%'  or a.u_title like '%{$keyword}%')";
         }
         if($gid!=''  ){
             $isql.=" and  a.u_group='$gid' ";
         }
         if($deptchoice!=""){
             $isql.=" and a.u_gid = '$deptchoice'";
         }
         // ,{$pre}admin_group b,{$pre}shops c  a.u_group=b.id and a.u_gid=c.id
         $query = $db->query("select a.*,(select title from {$pre}admin_group where id=a.u_group   ) title from {$pre}admin a where 1=1  $isql2 $isql  ORDER BY a.u_id desc  LIMIT $min,$rows");
         while($rs = $db->fetch_array($query)){
             ?>
             <tr class="text-c">
                 <td><?=$rs['u_id']?></td>
                 <td><?=$rs['u_name']?></td>

                 <td><?=$rs['u_title']?></td>
                 <td><?=$rs['u_phone']?></td>
                 <td><?=dianpu($rs['u_gid'])?></td>
                  
                 <td><?=$rs['title']?></td>
                 <td><?=date("Y-m-d H:i:s",$rs['u_time'])?></td>
                 <td class="admin-status"><?php echo $rs['u_or']==1?'<span class="label label-success">已启用</span>':'<span class="label">已停用</span>';?></td>
                 <td class="f-14 admin-manage"><?php /*?><a style="text-decoration:none" onClick="admin_stop(this,'10001')" href="javascript:;" title="停用"><i class="icon-hand-down"></i></a> <?php */?><a title="编辑" href="javascript:;" onClick="article_class_edit('<?=$rs['u_id']?>','1000','600','员工管理','admin.php?action=reg&uid=<?=$rs['u_id']?>&backurl=<?=base64_encode($WEBURL)?>')" class="ml-5" style="text-decoration:none"><i class="icon-edit"></i></a>
                     <?php if($adminarr['u_group']==1){?>
                     <a title="删除" href="admin.php?del=del&id=<?=$rs['u_id']?>" onClick="if(confirm('是否真的要删除本信息')){location.href=''+this.href};return false;" class="ml-5" style="text-decoration:none"><i class="icon-trash"></i></a></td>
                 <?php } ?>
             </tr>
             <?php
         }
         ?>
         <tr class="text-c">
             <td colspan="9"><?=getpage(" {$pre}admin a ","where 1=1 $isql2 $isql","?keyword=$keyword&gid=$gid&deptchoice=$deptchoice",$rows)?></td>
         </tr>
         </tbody>
     </table>

</div>
<?php
}
?>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/Validform_v5.3.2_min.js"></script> 
<script type="text/javascript" src="layer/layer.min.js"></script>
<script type="text/javascript" src="js/H-ui.js"></script>
<script type="text/javascript" src="js/H-ui.admin.js"></script>
<script type="text/javascript">
$(".Huiform").Validform(); 
</script>

</body>
</html>








